<!DOCTYPE html>
<html>

<head>
    <title>RoveCoder集约化管理平台</title>

    <meta name="keywords" content="" />

    <meta name="description" content="" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="/static/uc/css/theme.css" rel="stylesheet">
    <link href="/static/uc/lib/layui/css/layui.css" rel="stylesheet">
    <link href="/static/uc/css/login.css" rel="stylesheet">
    <style>
        <?php
        if (isset($SyscnfUcenterinfo) && $SyscnfUcenterinfo && $SyscnfUcenterinfo['welcomepic']) {
        ?>.xcpic {
            background-image: url('<?php echo $SyscnfUcenterinfo['welcomepic'] ?>');
        }

        <?php
        }
        ?>
    </style>
</head>

<body>
    <div class="loginbox">
        <div class="loginform">
            <h2>账户注册</h2>
            <div style="padding-top: 10px;">


                <div class=" rc-pagepadding">
                    <form class="layui-form" lay-filter="login-form">

                        <?php

                        foreach ($registerfields as $field) {
                        ?>
                            <div class="layui-form-item">
                                <label class="layui-form-label"><?php echo $field['title'] ?>：</label>
                                <div class="layui-input-block">
                                    <?php echo element($field['element'], name: $field['name'], sourcetype: $field['sourcetype'], sourceval: $field['sourceval'], require: 1) ?>
                                </div>

                            </div>


                            <?php
                            if ($field['name'] == 'pwd') {
                            ?>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">确认<?php echo $field['title'] ?>：</label>
                                    <div class="layui-input-block">
                                        <?php echo element($field['element'], name: 'repwd', sourcetype: $field['sourcetype'], sourceval: $field['sourceval'], require: 1); ?>
                                    </div>

                                </div>
                            <?php
                            }
                            ?>
                        <?php
                        } ?>


                        <div class="layui-form-item">
                            <div class="layui-inline" style="position: relative;margin-right:0">
                                <input type="hidden" id="captchatype" value="<?php echo $config['captchatype'] ?>" />
                                <?php
                                if ($config['captchatype'] == 1) {
                                ?>
                                    <div class="captchbox" id="captchbox">

                                        <div class="layui-form- " style="padding: 0!important;">
                                            <img src="" id="captchaimg" width="289" height="60" />
                                        </div>
                                    </div>
                                <?php
                                } else {
                                ?>
                                    <div class="captchbox" id="captchbox">
                                        <div class="layui-input-inline layui-input-wrap" style="width: 162px;">
                                            <input id="captcha" type="text" name="captcha" autocomplete="off" placeholder="请输入验证码" lay-reqtext="" lay-affix="clear" class="layui-input " />
                                        </div>
                                        <div class="layui-form-mid " style="padding: 0!important; width:150px">
                                            <img src="" id="captchaimg" width="150" height="40" />
                                        </div>
                                        <div class="layui-form-mid " style="padding: 0!important;margin-right:0!important">
                                            <button type="button" class="layui-btn layui-btn-primary" id="sendsms">发送</button>
                                        </div>
                                    </div>
                                <?php
                                }
                                ?>


                                <label class="layui-form-label">图形验证：</label>
                                <div class="layui-input-inline layui-input-wrap" style="width: 202px;">
                                    <input type="text" id="realcaptcha" name="realcaptcha" lay-verify="required" autocomplete="off" lay-reqtext="请写验证码" lay-affix="clear" class="layui-input " />
                                </div>

                                <div class="layui-form-mid " style="padding: 0!important;margin-right:0!important">
                                    <button type="button" class="layui-btn " id="showcaptch">获取验证码</button>
                                </div>

                            </div>
                        </div>



                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button type="button" class="layui-btn layui-btn-primary" lay-submit lay-filter="register_submit">注册</button>
                            </div>

                        </div>
                    </form>

                </div>







            </div>
            <hr>
            <div class="copyright">
                <p> © <?php echo date('Y') ?> RC集约化管理平台 . All rights RoveCoder </p>
            </div>
        </div>
        <div class="xcpic">

        </div>
    </div>
    <script src="/static/admin/lib/jquery/jquery.min.js"></script>
    <script src="/static/uc/lib/layui/layui.js"></script>
    <script src="/static/uc/lib/toastr/toastr.min.js"></script>
    <link href="/static/uc/lib/toastr/toastr.min.css" rel="stylesheet">
    <script src="/static/uc/js/rovecoder.js"></script>
    <script>
        layui.use(function() {
            var $ = layui.jquery;
            var layer = layui.layer;
            var form = layui.form;
            var element = layui.element;

            $('#captchaimg').click(function() {
                $('#captchaimg').attr('src', '/uc/Logreg/captcha?width=' + $('#captchaimg').attr('width') + '&height=' + $('#captchaimg').attr('height') + '&t=' + Math.random());
            });

            $('#showcaptch').click(function() {
                if (!$('#captchbox').is(":visible")) {
                    $('#captchaimg').attr('src', '/uc/Logreg/captcha?width=' + $('#captchaimg').attr('width') + '&height=' + $('#captchaimg').attr('height') + '&t=' + Math.random());
                    $('#captchbox').show();
                }
            });

            $(document).click(function(event) {
                var event = event.srcElement ? event.srcElement : event.target;

                if (event.id != 'showcaptch' && event.id != 'captcha' && event.id != 'captchaimg' && event.id != 'sendsms' && event.id != 'captchbox' && event.id != 'realcaptcha') {
                    $('#captchbox').hide();
                }

            });


            $('#sendsms').click(function() {
                if ($('#username').val() == '') {
                    layer.msg('请填写账户');
                    return;
                }
                if ($('#captcha').val() == '') {
                    layer.msg('请填写验证码');
                    return;
                }

                var sendparam = {
                    username: $('#username').val(),
                    captcha: $('#captcha').val(),
                    captchatype: $('#captchatype').val(),

                };
                if (sendparam.captchatype == 2) {
                    sendparam.phone = $('#phone').val()
                }

                if (sendparam.captchatype == 3) {
                    sendparam.email = $('#email').val()
                }


                $.ajax({
                    url: '/uc/Logreg/regSendsms', //请求路径
                    type: "POST", //请求方式
                    data: sendparam, // 默认写法
                    success: function(data) {
                        if (data.code == 0) {
                            countdown('showcaptch', 60);
                            $('#captchbox').hide();
                        } else {
                            layer.msg(data.message);
                            $('#captchaimg').attr('src', '/uc/Logreg/captcha?width=' + $('#captchaimg').attr('width') + '&height=' + $('#captchaimg').attr('height') + '&t=' + Math.random());
                        }
                    },
                    error: function() {

                    },

                });
            });


            //按钮倒计时
            function countdown(btn, seconds) {
                $('#' + btn).attr('disabled', true); // 禁用按钮
                $('#' + btn).text('已发送(' + seconds + ')'); // 按钮显示倒计时时间

                if (seconds > 0) {
                    seconds--; // 更新剩余秒数
                    setTimeout(function() {
                        countdown(btn, seconds); // 递归调用自己，实现倒计时
                    }, 1000); // 延迟 1 秒执行
                } else {
                    $('#' + btn).attr('disabled', false); // 恢复按钮可用
                    $('#' + btn).text('重新获取');
                }
            }




            form.on('submit(register_submit)', function(data) {
                $.ajax({
                    url: '/uc/Logreg/register', //请求路径
                    type: "POST", //请求方式
                    data: data.field, // 默认写法
                    success: function(data) {
                        if (data.code == 0) {
                            toastr_success("注册成功", function() {
                                window.parent.location.href = '/uc/Logreg/index';
                            });
                        } else {
                            toastr_error(data.message);


                        }
                    },
                    error: function() {

                    },

                });
            });

        });
    </script>
</body>

</html>